package com.qf.sclg.service.impl;

import com.qf.sclg.dao.PicDao;
import com.qf.sclg.entity.Pic;
import com.qf.sclg.result.ResponseCode;
import com.qf.sclg.result.ResponseData;
import com.qf.sclg.service.PicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Pic)表服务实现类
 *
 * @author makejava
 * @since 2021-10-13 10:39:59
 */
@Service("picService")
public class PicServiceImpl implements PicService {
    @Resource
    private PicDao picDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pId 主键
     * @return 实例对象
     */
    @Override
    public Pic queryById(Integer pId) {
        return this.picDao.queryById(pId);
    }

    /**
     * 新增数据
     *
     * @param pic 实例对象
     * @return 实例对象
     */
    @Override
    public Pic insert(Pic pic) {
        this.picDao.insert(pic);
        return pic;
    }

    /**
     * 修改数据
     *
     * @param pic 实例对象
     * @return 实例对象
     */
    @Override
    public Pic update(Pic pic) {
        this.picDao.update(pic);
        return this.queryById(pic.getPId());
    }

    /**
     * 通过主键删除数据
     *
     * @param pId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pId) {
        return this.picDao.deleteById(pId) > 0;
    }

    @Override
    public ResponseData queryByType(String type, Integer status) {
        if(type !=null && type != ""){
            if(status != 1 && status != 0){
                status = 1;
            }
            List<Pic> pics = picDao.queryByType(type,status);
            return new ResponseData(pics);


        }else {
            return new ResponseData(ResponseCode.ERROR);
        }

    }
}
